package com.huirui.server.controller.admin;

import com.huirui.server.pojo.dto.BrandDto;
import com.huirui.server.pojo.entity.Brand;
import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.service.BrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController("adminBrandController")
@RequestMapping("/admin/brand")
@Slf4j
@Validated
@Tag(name = "品牌管理", description = "微信小程序品牌管理")
@RequiredArgsConstructor
public class BrandController {

    public final BrandService brandService;


    @PostMapping("/add/brand")
    @Operation(summary = "新增品牌")
    public Result<Void> addNewBrand(@RequestBody @Validated BrandDto brandDto) {
        brandService.addNewBrand(brandDto);
        return Result.success();
    }

    @GetMapping("/list")
    @Operation(summary = "获取品牌列表")
    public Result<PageResult<Brand>> listBrand(@RequestParam(value = "brandName", required = false) String brandName, int page, int pageSize) {
        PageResult<Brand> res = brandService.listBrand(brandName, page, pageSize);
        return Result.success(res);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除某品牌")
    public Result<Void> deleteBrand(@PathVariable Long id) {
        brandService.deleteBrand(id);
        return Result.success();
    }

    @PutMapping("/update/brand")
    @Operation(summary = "修改品牌")
    public Result<Void> updateBrand(@RequestBody @Validated BrandDto brandDto) {
        brandService.updateBrand(brandDto);
        return Result.success();
    }
}
